﻿using RpcStore.DAL;
using RpcStore.DAL.Model;
using WeDonekRpc.Client.Attr;
using WeDonekRpc.Client.Interface;
using WeDonekRpc.Helper;

namespace RpcStore.Collect.LocalEvent
{
    [LocalEventName("Delete")]
    internal class DeleteRpcMerEvent : IEventHandler<Model.RpcMerEvent>
    {
        private readonly IServerTransmitSchemeDAL _SchemeDAL;
        private readonly IServerTransmitConfigDAL _BasicDAL;
        public DeleteRpcMerEvent (IServerTransmitSchemeDAL schemeDAL, IServerTransmitConfigDAL basicDAL)
        {
            this._SchemeDAL = schemeDAL;
            this._BasicDAL = basicDAL;
        }

        public void HandleEvent (Model.RpcMerEvent data, string eventName)
        {
            BasicScheme[] scheme = this._SchemeDAL.Clear(data.RpcMer.Id);
            if (scheme.IsNull())
            {
                return;
            }
            long[] ids = scheme.Convert(c => !c.IsAuto, c => c.Id);
            if (ids.Length > 0)
            {
                this._BasicDAL.Delete(ids);
            }
        }
    }
}
